package com.woniu.userservice.dao;

import com.woniu.userservice.dto.BiddingsDTO;
import com.woniu.userservice.entity.Biddings;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface BiddingsDao {
    Biddings queryById(Integer id);

    List<Biddings> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
    
    List<Biddings> findAll();

    List<Biddings> queryAll(Biddings biddings);

    int insert(Biddings biddings);

    int update(Biddings biddings);

    int deleteById(Integer id);

    @Delete("delete * from biddings where id = #{id} and userId = #{userId}")
    void deleteByUserId(@Param("id") Integer id, @Param("userId") Integer userId);

    /**
     *
     * @param goodsName 商品名字
     * @param userId 用户id
     * @param price 用户价格
     * @param biddingTime 时间
     * @return 查询的东西
     */
    List<Biddings> findByMsg(@Param("goodsName") String goodsName, @Param("userId") Integer userId, @Param("price") Double price, @Param("buddingTime") Date biddingTime);

    /**
     *
     * @param goodsid
     * @return
     */
    @Select("SELECT userId,COUNT(*) binddingnum,SUM(price) sumprice FROM biddings WHERE goodsId=#{goodsid} GROUP BY userId;")
    List<BiddingsDTO> queryByGoodsid(Integer goodsid);
}